import 'package:syria_sports/presentation/admin_home_tabs/coaches_tab/widgets/coach_item_view.dart';

import '../../../../core/app_export.dart';
import '../../../../widgets/app_bar/appbar_subtitle.dart';
import '../../../../widgets/app_bar/custom_app_bar.dart';
import '../../../../widgets/app_bar/outline_icon_button.dart';
import '../../../../widgets/custom_rating_bar.dart';
import '../../../../widgets/screen_state_widget.dart';
import 'public_coaches_tab_cubit.dart';
import 'package:flutter/material.dart';

class PublicCoachesTabScreen extends StatelessWidget {
  const PublicCoachesTabScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    double height = MediaQuery.of(context).size.height;
    double width = MediaQuery.of(context).size.width;

    var coachesCubit = PublicCoachesTabCubit();

    return Scaffold(
      appBar: _buildAppBar(context: context,cubit: coachesCubit),
      body: BlocProvider<PublicCoachesTabCubit>(
        create: (context) => coachesCubit..init(),
        child: BlocConsumer<PublicCoachesTabCubit, PublicCoachesTabState>(
          listener: (context, state) {
            // TODO: implement listener
          },
          builder: (context, state) {
            var cubit = PublicCoachesTabCubit.get(context);

            return Container(
              height: height,
              width: width,
              decoration: BoxDecoration(
                image: DecorationImage(
                  image: AssetImage(ImageConstant.imgBackground),
                  fit: BoxFit.cover,
                ),
              ),
              child: ScreenStateWidget(
                isDone: state is PublicCoachesTabDone,
                isError: state is PublicCoachesTabError,
                isLoading: state is PublicCoachesTabLoading,
                onRefresh: cubit.getAllUsers,
                onDone: GridView.builder(
                    gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
                      maxCrossAxisExtent: 400,
                      mainAxisExtent: 150,
                      //childAspectRatio:(height>width)? height/width:width/height,
                    ),
                    itemCount: cubit.users.length,
                    itemBuilder: (context,index){
                      return CoachItemView(user: cubit.users[index]);
                    }),
              ),

            );
          },
        ),
      ),
    );
  }
  PreferredSizeWidget _buildAppBar({required BuildContext context , required PublicCoachesTabCubit cubit}) {
    return CustomAppBar(
      title: AppbarSubtitle(text: 'المدربين'),
      leading: OutlineIconButton(
        imagePath: ImageConstant.imgRightIcon,
        onTapped: (){
          Navigator.pop(context);
        },
      ),
    );
  }
}
